package com.iss.umservice.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Service;

import com.iss.umservice.bean.ServiceApplyBean;
import com.iss.umservice.bean.ServiceBean;
import com.iss.umservice.dao.ServiceDao;

@Service
public class ServiceDaoImpl extends SqlMapClientDaoSupport implements
		ServiceDao {

	public ServiceBean queryServiceInfo(String serviceID) {
		// TODO Auto-generated method stub
		return (ServiceBean) getSqlMapClientTemplate().queryForObject(
				"service.queryServiceInfo", serviceID);
	}

	public List<ServiceBean> queryServiceList(ServiceBean serviceBean,
			int offset, int row) {
		// TODO Auto-generated method stub
		return (List<ServiceBean>) getSqlMapClientTemplate().queryForList(
				"service.queryServiceList", serviceBean, offset, row);
	}

	public void createService(ServiceBean servicebean) {
		// TODO Auto-generated method stub
		getSqlMapClientTemplate().insert("service.createService", servicebean);

	}

	public void modService(ServiceBean servicebean) {
		// TODO Auto-generated method stub
		getSqlMapClientTemplate().update("service.modService", servicebean);

	}

	public int countServiceInfo(ServiceBean serviceBean) {
		// TODO Auto-generated method stub

		int userAccounts = ((Integer) getSqlMapClientTemplate().queryForObject(
				"service.countServiceInfo", serviceBean)).intValue();

		return userAccounts;
	}

	public void delService(String serviceID) {
		// TODO Auto-generated method stub
		getSqlMapClientTemplate().update("service.delService", serviceID);
	}

	public void applyService(ServiceApplyBean serviceApplyBean) {
		// TODO Auto-generated method stub
		getSqlMapClientTemplate().insert("service.applyService",
				serviceApplyBean);
	}

	public void approveService(ServiceApplyBean serviceApplyBean) {
		// TODO Auto-generated method stub
		getSqlMapClientTemplate().update("service.approveService",
				serviceApplyBean);
	}

	public void delServiceApplyInfo(String iD) {
		// TODO Auto-generated method stub
		getSqlMapClientTemplate().delete("service.delServiceApplyInfo", iD);
	}

	public int countServiceApplyInfo(ServiceApplyBean serviceApplyBean) {
		// TODO Auto-generated method stub
	   //如果是申请导师，则关联查询导师表
	    if("3".equals(serviceApplyBean.getType()))
	    {
	        return ((Integer) getSqlMapClientTemplate().queryForObject(
                "service.countTutorApplyInfo", serviceApplyBean)).intValue();
	    }
	    else {
	        return ((Integer) getSqlMapClientTemplate().queryForObject(
                "service.countServiceApplyInfo", serviceApplyBean)).intValue(); 
        }

	}

	public List<ServiceApplyBean> queryServiceApplyList(
			ServiceApplyBean serviceApplyBean, int offset, int rowSize) {
		// TODO Auto-generated method stub
	    if("3".equals(serviceApplyBean.getType()))
	    {
		return (List<ServiceApplyBean>) getSqlMapClientTemplate().queryForList(
				"service.queryTutorApplyList", serviceApplyBean, offset,
				rowSize);
	    }
	    else {
	        return (List<ServiceApplyBean>) getSqlMapClientTemplate().queryForList(
                "service.queryServiceApplyList", serviceApplyBean, offset,
                rowSize);
        }
	}

	public boolean isApplyed(ServiceApplyBean serviceApplyBean) {
		// TODO Auto-generated method stub
		if (((Integer) getSqlMapClientTemplate().queryForObject(
				"service.isApplyed", serviceApplyBean)).intValue() > 0) {
			return true;
		}
		return false;
	}

	public List<ServiceApplyBean> queryMeetingApplyInfo(String serviceId) {
		// TODO Auto-generated method stub		
		return getSqlMapClientTemplate().queryForList("service.queryMeetingApplyInfo",serviceId);
	}

}
